package cn.lili.controller.feign.store;

import cn.lili.common.security.enums.SceneEnums;
import cn.lili.modules.operationcenter.entity.vos.UrbanStationSearchParams;
import cn.lili.modules.store.client.StoreClient;
import cn.lili.modules.store.entity.dos.Store;
import cn.lili.modules.store.entity.dto.StoreSearchPageParams;
import cn.lili.modules.store.entity.dto.StoreSearchParams;
import cn.lili.modules.store.entity.params.StoreParams;
import cn.lili.modules.store.entity.vos.StoreVO;
import cn.lili.modules.store.service.StoreService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 店铺 feign client
 *
 * @author Chopper
 * @version v1.0
 * 2021-11-17 18:06
 */
@RestController
@RequiredArgsConstructor
public class StoreFeignController implements StoreClient {

    private final StoreService storeService;

    @Override
    public StoreVO getStoreDetailVO(String id) {
        return storeService.getStoreDetailVO(id);
    }


    @Override
    @Transactional
    @ShardingTransactionType(TransactionType.BASE)
    public Store customAdd(Store store) {
        return storeService.customAdd(store);
    }

    @Override
    @Transactional
    @ShardingTransactionType(TransactionType.BASE)
    public Store customEdit(Store store) {
        return storeService.customEdit(store);
    }


    @Override
    public StoreVO getStore(String storeId) {
        return storeService.getStoreDetailVO(storeId);
    }

    /**
     * 列表查询
     *
     * @param searchParams 查询参数
     * @return 店铺列表
     */
    @Override
    public List<Store> list(StoreSearchParams searchParams) {
        return storeService.list(searchParams);
    }


    /**
     * 更新评分
     *
     * @param storeParams 店铺参数
     * @return 操作结果
     */
    @Override
    @Transactional
    @ShardingTransactionType(TransactionType.BASE)
    public void updateScore(StoreParams storeParams) {

        storeService.updateScore(storeParams.getStoreId(),
                storeParams.getDeliveryScore(),
                storeParams.getServiceScore(),
                storeParams.getDescriptionScore());
    }

    @Override
    public void updateStoreGoodsNum(String storeId, Long num) {
        storeService.updateStoreGoodsNum(storeId, num);
    }

    @Override
    @Transactional
    @ShardingTransactionType(TransactionType.BASE)
    public void enable(String storeId) {
        storeService.enable(storeId);
    }

    @Override
    public Page<StoreVO> page(StoreSearchPageParams storeSearchPageParams) {
        return storeService.findByConditionPage(storeSearchPageParams.getStoreSearchParams(), storeSearchPageParams.getPage());
    }

    @Override
    @Transactional
    @ShardingTransactionType(TransactionType.BASE)
    public void disable(String storeId) {
        storeService.disable(storeId);
    }

    @Override
    public Store getStoreDetailBySceneAndUserId(String extendId, SceneEnums scene) {
        return storeService.getStoreDetailBySceneAndUserId(extendId, scene);
    }

    @Override
    public Store getStoreByManagerId(String managerId, SceneEnums scene) {
        return storeService.getStoreByManagerId(managerId, scene);
    }


    @Override
    public List<Store> getSupplierListByUrbanId(String urbanId) {
        return storeService.getSupplierListByUrbanId(urbanId);
    }

    /**
     * 获取当前运营中心的有多少供应商
     * @return 供应商列表
     */
    @Override
    public List<Store> getStoreList() {
        return storeService.getStoreList();
    }
    @Override
    public Long getCurrentMonthSupplierCountByUrbanId(String urbanId) {
        return storeService.getCurrentMonthSupplierCountByUrbanId(urbanId);
    }

    @Override
    public Long getSupplierListByParams(UrbanStationSearchParams params) {
        return storeService.getSupplierListByParams(params.getUrbanId(), params.getStartTime(), params.getEndTime());
    }

}
